package com.jwdf.uda.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemVoteOptionBinding;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class VoteOptionAdapter extends AbsAdapter<PbBean.PbBaseVoterInfo> {

    public VoteOptionAdapter(Context context) {
        super(context);
    }

    @Override
    protected AbsViewHolder onCreateViewHolder(ViewGroup parent, int itemType) {
        return new VoteOptionViewHolder(mInflater.inflate(R.layout.item_vote_option, parent, false));
    }

    private class VoteOptionViewHolder extends AbsViewHolder<PbBean.PbBaseVoterInfo> {
        private ItemVoteOptionBinding mItemBinding;

        public VoteOptionViewHolder(View convertView) {
            super(convertView);
            mItemBinding = DataBindingUtil.bind(convertView);
            convertView.setOnClickListener(this);
        }

        @Override
        protected void onBindView(PbBean.PbBaseVoterInfo item) {
            if (item == null) return;
            ImageLoader.getInstance().displayImage(item.getVoterInfo().getAvatar().getUrl(), mItemBinding.ivHeader);
            mItemBinding.tvName.setText(StringUtils.filterNullAndTrim(item.getVoterInfo().getNickname()));
            mItemBinding.setIsDesigner(item.getVoterInfo().getIsDesigner());
            mItemBinding.tvIntroduction.setVisibility(TextUtils.isEmpty(StringUtils.filterNullAndTrim(item.getVoterInfo().getIntroduction())) ? View.GONE:View.VISIBLE);
            mItemBinding.tvIntroduction.setText(item.getVoterInfo().getIntroduction());
        }

        @Override
        public void onClick(View v) {
            UserInfoActivity.start(v.getContext(), item.getVoterInfo().getUserId(), item.getVoterInfo().getIsDesigner());
        }
    }
}
